package com.fitbet.wechat.web.controller.main;

import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.demo2do.core.entity.exception.BusinessException;
import com.demo2do.core.entity.result.HttpResult;
import com.fitbet.entity.user.User;
import com.fitbet.wechat.service.UserBetService;
import com.fitbet.wechat.web.resolver.Secure;

/**
 * 
 * @author mohanlan
 *
 */
@RestController
@RequestMapping(value = "/userbets")
public class UserBetSupportController {
    
    private static final Logger logger = LoggerFactory.getLogger(UserBetSupportController.class);
    
    @Autowired
    private UserBetService userBetService;
    
    /**
     * 
     * @return
     */
    @RequestMapping(value = "/{id}/support", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public HttpResult onSupport(@Secure User user,
                                @PathVariable("id") Long userBetId,
                                @RequestParam("support") boolean support) {
        
        HttpResult httpResult = new HttpResult();
        
        try {
            
            Map<String, Object> data = userBetService.createUserBetSupport(user, userBetId, support);
            return httpResult.success().message("创建数据成功").data(data);
            
        } catch (Exception e) {
            logger.error("onCreateUserBetSupport error: ", e);
            throw BusinessException.newInstance("500", "创建数据失败");
        }
        
    }
}
